package com.bwie.house.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.house.entity.AddressEntity;
import com.bwie.house.service.AddressService;
import com.bwie.house.vo.FlatsSearchVo;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.house.entity.FlatsEntity;
import com.bwie.house.service.FlatsService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 
 *
 * @author wangguohai
 * @email 270901876@qq.com
 * @date 2022-04-21 20:35:03
 */
@Slf4j
@RestController
@RequestMapping("house/flats")
public class FlatsController {
    @Autowired
    private FlatsService flatsService;

    @Autowired
    private AddressService addressService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = flatsService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/getHouse")
    public FlatsEntity getHouse(@RequestParam("flatsId") Integer flatsId){
        return flatsService.getById(flatsId);
    }


    /**
    * @author 張泽宇
    * @date 2022/4/26 13:33
    * @return
    */
    @RequestMapping("/FlatsEsList")
    public R FlatsEsList(@RequestBody FlatsSearchVo flatsSearchVo){

        log.info("FlatsEsList方法正在执行");

        PageUtils page = flatsService.FlatsEsList(flatsSearchVo);

        return R.ok().put("page", page);
    }

    /**
    * @author 張泽宇
    * @date 2022/5/2 15:31
    * @return
    */
    @RequestMapping("/xian3")
    public R xian3(){

        List<AddressEntity> level = addressService.list(new QueryWrapper<AddressEntity>().eq("level", 3));

        return R.ok().put("data", level);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{flatsId}")
    public R info(@PathVariable("flatsId") Integer flatsId){
		FlatsEntity flats = flatsService.getById(flatsId);

        return R.ok().put("flats", flats);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FlatsEntity flats){
		flatsService.save(flats);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FlatsEntity flats){
		flatsService.updateById(flats);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] flatsIds){
		flatsService.removeByIds(Arrays.asList(flatsIds));

        return R.ok();
    }

}
